var teamId;
var teamName;
var tmGameId;
var gameTechList={};
$(document).ready(function(){ 
	$('#header').animate({'top':'0px'},400);
	teamId = args.teamId; //取得id的值
	teamName = args.teamName;
	tmGameId = args.tmGameId;
	
	var paraData = {teamId:teamId,tmGameId:tmGameId};
	$.getJSON(path+"/soccer/teamGameAction!selectForGameTech.action",paraData, function(data){
		  gameTechList = data.gameTechList;
	  	  var gameTechHtml=[];
	  	  $.each(gameTechList,function(index,obj){
	  		gameTechHtml.push("<tr>");
	  		gameTechHtml.push("<input type='hidden' id='gameTechList["+index+"].teamId' name='gameTechList["+index+"].teamId' value='"+obj.teamId+"'/>");
	  		gameTechHtml.push("<input type='hidden' id='gameTechList["+index+"].tmGameId' name='gameTechList["+index+"].tmGameId' value='"+obj.tmGameId+"'/>");
	  		gameTechHtml.push("<input type='hidden' id='gameTechList["+index+"].playUserId' name='gameTechList["+index+"].playUserId' value='"+obj.playUserId+"'/>");
	  		gameTechHtml.push("<td nowrap='nowrap' style='font-size:20px'>"+obj.playUserNo+"</td>");
	  		gameTechHtml.push("<td nowrap='nowrap' style='font-size:20px'>"+obj.playUserName+"</td>");
//	  		gameTechHtml.push("<td>");
//	  		gameTechHtml.push("<select id='gameTechList["+index+"].playFlag' name='gameTechList["+index+"].playFlag' onchange='playFlagChanged("+index+",this)'>");//onchange='playFlagChanged("+index+")'  		
//	  		if(obj.playFlag=='1'||obj.playFlag==undefined||obj.playFlag==''){
//	  			obj.playFlag = "1";
//	  			gameTechHtml.push("<option value='1' selected='selected'>上场</option>");
//	  			gameTechHtml.push("<option value='0'>未上场</option>");
//	  		}else{
//	  			obj.playFlag = "0";
//	  			gameTechHtml.push("<option value='1'>上场</option>");
//	  			gameTechHtml.push("<option value='0' selected='selected'>未上场</option>");
//	  		}
//	  		gameTechHtml.push("</select>");
//	  		gameTechHtml.push("</td>");
	  		gameTechHtml.push("<td nowrap='nowrap' style='font-size:20px'>");
	  		gameTechHtml.push("<input id='min' name='' type='button'  value='-' onclick='minus("+index+")'/>");
	  		gameTechHtml.push("<input id='gameTechList["+index+"].techScore' onchange='scoreChanged("+index+")' onkeydown='validateNumber(event,"+index+")' name='gameTechList.techScore' type='text' value='"+obj.techScore+"' type='number' onclick='this.select();' style='width:80px'/>");
	  		gameTechHtml.push("<input id='add' name='' type='button' value='+' onclick='add("+index+")'/>");
	  		gameTechHtml.push("</td>");
	  		gameTechHtml.push("</tr>");
	  		//teamHtml.push("<tr class='info'><td>"+obj.taskDetail+"</td><td>"+obj.sendUserName+"</td><td>"+moment(obj.sendTime,"YYYY-MM-DD HH:mm:ss").format("YYYY-MM-DD HH:mm:ss")+"</td></tr>");
//	  		$("#gameTechList["+index+"].playFlag").change(function(){
//		  		gameTechList[index].playFlag=$(this).val();debugger;
//		  	}); 
	  	  });
	  	  $("#gameTechBody").html(gameTechHtml.join(""));  
	});
	
	$("#submitBtn").click(function(){
//		var techForm = $("#techForm");
//		techForm.submit();
		
		var jsonStr = JSON.stringify(gameTechList);
		$.post(path+"/soccer/teamGameAction!gameTechSubmit.action",{teamId:teamId,tmGameId:tmGameId,jsonStr:jsonStr}, function(data){
			strMessage = data.strMessage;
			$('#strMessage').text(strMessage);
		},'json');
	});
});
function goBack(){
	window.location.href=path+"/soccer/teamGame.jsp?teamId="+teamId+"&teamName="+teamName;
}
function add(index){
	var t = $("input[id='gameTechList["+index+"].techScore']");
	var score = parseFloat(t.val());
	t.val(isNaN(score)?0.5:score+0.5);
	scoreChanged(index);
}
function minus(index){
	var t = $("input[id='gameTechList["+index+"].techScore']");
	var score = parseFloat(t.val());
	t.val(isNaN(score)?0:score-0.5);
	scoreChanged(index);
}
function scoreChanged(index){
	var t = $("input[id='gameTechList["+index+"].techScore']");
	var score = parseFloat(t.val());
	if(score<0||score>10){
		alert("评分在0-10分之间。");
		t.val(gameTechList[index].techScore);
	}else{
		gameTechList[index].techScore=score;
	}
}
function playFlagChanged(index,obj){
	gameTechList[index].playFlag=obj.value;
}
//限制只能输入数字
function validateNumber(e,index){
	var code = parseInt(window.event ? e.keyCode:e.which);
    if (code >= 96 && code <= 105 || code >= 48 && code <= 57 || code == 8 || code==110 || code==190) {  
        return true;  
    } else {  
    	alert("只能输入小数！");
    	var t = $("input[id='gameTechList["+index+"].techScore']");
    	t.val(gameTechList[index].techScore);
        return false;
    }
}